package com.orm.handler;

import java.sql.*;
import java.time.LocalTime;


public class LocalTimeTypeHandler extends BaseTypeHandler<LocalTime>{
	@Override
	public void setNotNullParameter(PreparedStatement ps, int i, LocalTime parameter, JDBCType jdbcType) throws SQLException {
		ps.setTime(i, Time.valueOf(parameter));
	}
	
	@Override
	public LocalTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
		return getLocalTime(rs.getTime(columnName));
	}
	
	@Override
	public LocalTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return getLocalTime(rs.getTime(columnIndex));
	}
	
	public LocalTime getLocalTime(Time time){
		if(time != null){
			return time.toLocalTime();
		}
		return null;
	}
}
